begintownscript;

variables;
short bmessage,pcs,seated,leadchar,rctx,rcty,sdf_counter;
string custom_m;

body;

beginstate INIT_STATE;

	turn_off_training(1);
	set_crime_tolerance(5);

	if(get_flag(1,0) == 0){
		leadchar = 0;
		while(char_ok(leadchar) == FALSE){
			leadchar = (leadchar + 1);
		}
		pcs = (leadchar + 1);
		while (pcs <= 3){
			erase_char(pcs);
			pcs = (pcs + 1);
		}
		set_name(leadchar,"Capitain Maverick");
		set_level(leadchar,10);
		sdf_counter = 0;
		while(sdf_counter <= 22){
			set_char_trait(leadchar,sdf_counter,0);

			sdf_counter = (sdf_counter + 1);
		}
		alter_stat(leadchar,0,(5 - get_stat(leadchar,0)));
		alter_stat(leadchar,1,(5 - get_stat(leadchar,1)));
		alter_stat(leadchar,2,(2 - get_stat(leadchar,2)));
		alter_stat(leadchar,3,(7 - get_stat(leadchar,3)));
		alter_stat(leadchar,4,(4 - get_stat(leadchar,4)));
		alter_stat(leadchar,5,(4 - get_stat(leadchar,5)));
		sdf_counter = 6;
		while(sdf_counter <= 31){
			alter_stat(leadchar,sdf_counter,(0 - get_stat(leadchar,sdf_counter)));

			sdf_counter = (sdf_counter + 1);
		}
		change_coins(0 - coins_amount());
		sdf_counter = 0;
		while(sdf_counter <= 12){
			destroy_char_item(leadchar,sdf_counter);

			sdf_counter = (sdf_counter + 1);
		}
		while(item_type_in_slot(leadchar,13) != -1){
			destroy_char_item(leadchar,13);
		}

		relocate_character(leadchar,34,25);
		set_character_facing(leadchar,4);
		force_view_center(34,25);
		force_instant_terrain_redraw();
		pause(5);

		reset_dialog();
		add_dialog_str(0,"General Byron has been reduced to his last ounce of energy.  I am not surprised; Lord Ameron's forces have been pounding Thermidor's walls relentlessly.  The mountain citadel occupies a key bottleneck, but its supply lines have recently been cut off.",0);
		add_dialog_str(1,"Thermidor is a mining city perched atop the mountain of the same name.  It was built expecting an attack, and it expected one rightfully:  It is here.",0);
		add_dialog_str(2,"Thermidor is not expected to last.  Certainly, some of Ameron's forces have already slipped by its defenses.  But the moment Thermidor falls, all of Ameron's armies will flood into Lord Roshan's territory, freshly armed with Thermidor's finest steel.",0);
		add_dialog_str(3,"Our goal here is to act as a stopgap.  We are to give Lord Roshan enough time to gather up whatever men he can so that more of our bread basket is not lost to the enemy.",0);
		add_dialog_str(4,"Everyone here-- myself very much so as well-- is aware that their job is to die slowly.  Nobody has been taking it well, and everyone has been breaking just a little.  Underneath that armor, General Byron must be a mess.",0);
		add_dialog_str(5,"_Good to see you, Captain Maverick..._",15);
		add_dialog_choice(0,"Me too, sir.");
		bmessage = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"_Captain.  I don't know if there's anything I can tell you that you can't already see.  But I had figured that I might as well use my time to make sure my subordinates are well-informed._",15);
		add_dialog_str(1,"_Our ramparts are holding up.  Their battering rams have had difficulties scaling the mountain, which is fortunate.  Unfortunately, our archers are running out of ammunition and we've resorted to dissembling building and using rocks as ammo._",15);
		add_dialog_str(2,"_Most of the able-bodied citizens whom we drafted into Roshan's Militia have died since we haven't been able to offer them much in the way of training.  Our medics are, as is usual, swamped._",15);
		add_dialog_str(3,"_On the upside, we've been able to prevent the enemy from attacking us from our entrance at the foot of the mountain.  The crevasses leading to the side entrance are too narrow for siege equipment to travel in that direction._",15);
		add_dialog_str(4,"_We have food still, although we've had to keep it on the low-down that we've been cannibalizing our former comrades' bodies in order to feed our own._",15);
		add_dialog_str(5,"_And...  no, I don't think I have any orders for you, Captain._",15);
		add_dialog_choice(0,"Then why did you summon me, sir?");
		bmessage = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"_I wanted to make sure you were here, Captain, so that you would know the situation.  I told you that already._",15);
		add_dialog_str(1,"He is not making sense.  He is also not doing much to boost morale.  Perhaps he has no morale left himself.  That would make sense.",0);
		add_dialog_str(2,"_Oh, and make sure to equip yourself.  I've left your equipment in Storeroom B.  You are dismissed, Captain._",15);
		add_dialog_choice(0,"Thank you, sir.");
		bmessage = run_dialog(1);

		// Armor
		put_item_on_spot(44,18,32);
		// Weapon
		put_item_on_spot(44,19,57);
		// Shield
		put_item_on_spot(44,20,131);
		// Helm
		put_item_on_spot(46,18,137);
		// Pants
		put_item_on_spot(46,19,495);
		// Bracers
		put_item_on_spot(46,20,323);

		set_flag(1,0,1);
		block_entry(1);

		print_str_color("NOTE: IMPORTANT!",1);
		print_str_color("Do NOT SAVE in this scenario!",1);
		print_str_color("I repeat:",1);
		print_str_color("Do NOT SAVE in this scenario AT ALL.",1);
	}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	leadchar = 0;
	while(char_ok(leadchar) == FALSE){
		leadchar = (leadchar + 1);
	}
	if((get_flag(1,0) >= 8) && (get_flag(1,0) < 10))
		inc_flag(1,0,1);
	if(get_flag(1,0) == 10){
		if(((char_loc_x(leadchar) >= 37) && (char_loc_x(leadchar) < 42)) && (char_loc_y(leadchar) <= 13)){
			set_flag(1,0,12);
		}
		else{
			message_dialog("_Psst.  Friend, come over here!_","That whispering came from the north.");
			set_flag(1,0,11);
		}
	}
	if(get_flag(1,0) >= 10){
		if(((char_loc_x(leadchar) >= 37) && (char_loc_x(leadchar) < 42)) && (char_loc_y(leadchar) <= 13)){
			if(get_flag(1,0) < 12){
				message_dialog("_Psst!  Maverick, to your left!_","The whispering is coming from the west.");
				set_flag(1,0,12);
				set_flag(6,0,1);
			}
		}
		else{
			if(get_flag(1,0) < 11)
				message_dialog("_Psst.  Friend, come over here!_","That whispering came from the north.");
			set_flag(1,0,11);
		}
	}

	if(get_crime_level() > 0){
		message_dialog("There are not many soldiers in Thermidor compared to how many are outside of it, but there are still many soldiers in Thermidor compared to me.  A trial by my peers is foregone in favor of an on-site execution.","");
		kill_char(1000,3,0);
	}

break;

beginstate 10;

	if(get_flag(1,0) < 2){
		message_dialog("The storerooms are to the east of here.  My equipment is in Storeroom B.","");
		set_flag(1,0,2);
	}

break;

beginstate 11;

	if(get_flag(2,0) == 0){
		message_dialog("This is my room.","");
		set_flag(2,0,1);
	}

break;

beginstate 12;

	if(get_flag(3,0) == 0){
		message_dialog("This is the mess hall.  General Byron was right; human stew is served here.  Many of the soldiers suspect this, since they too are curious as to whence their meals come, but they do not dare voice their doubts as such.","");
		set_flag(3,0,1);
	}

break;

beginstate 13;

	message_dialog("This is the way to leave the Command Center.  My presence is not needed at the gates or ramparts, though; many Privates have been temporarily and immediately promoted to Colonel or higher in order to oversee the immediate defenses of Thermidor.","My duties all rest entirely in the Command Center these days.");
	block_entry(1);

break;

beginstate 14;

	if(get_flag(1,0) == 4){
		march_party(41,19);
		force_view_center(41,19);
		force_instant_terrain_redraw();
		play_sound(49);
		pause(3);

		leadchar = 0;
		while(char_ok(leadchar) == FALSE){
			leadchar = (leadchar + 1);
		}
		set_character_facing(leadchar,0);
		force_instant_terrain_redraw();
		pause(3);

		set_character_facing(leadchar,4);
		force_instant_terrain_redraw();
		pause(3);

		set_character_facing(leadchar,0);
		force_instant_terrain_redraw();
		pause(2);

		set_character_facing(leadchar,4);
		force_instant_terrain_redraw();
		pause(2);

		set_character_facing(leadchar,0);
		force_instant_terrain_redraw();
		pause(2);

		reset_dialog();
		add_dialog_str(0,"This is strange.  Two soldiers are flanking me.  Are they in league with the soldier who spoke so oddly before?  This is strange indeed.",0);
		add_dialog_str(1,"_Captain Maverick...  hello.  You gave very good responses to the questions before.  Even when you lied, you showed competence.  If you answered the question honestly at first, then we'd have been skeptical._",15);
		add_dialog_str(2,"_You are amicable yet intelligent.  This is good, Captain.  Question is:  What is your plan now?_",15);
		add_dialog_str(3,"Being spoken to in this manner is very unsettling.  The archer likely realizes this.  I will answer him honestly.  I will tell him that I have no real...  plan.",0);
		add_dialog_choice(0,"I do not have a plan.");
		bmessage = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"_Good.  You are still being honest.  This too is admirable.  Your superiors do not have a plan either.  Perhaps they are not being intelligent, although it is highly doubtful that even a genius could save Thermidor at this point._",15);
		add_dialog_str(1,"_In fewer words:  Even if Lord Ameron's plan to use Thermidor to stop Roshan's advance is successful, it entails your death.  Do you want to die?_",15);
		add_dialog_str(2,"This is an obvious question.  Of course I do not want to die.",0);
		add_dialog_choice(0,"No, I do not want to die.");
		bmessage = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"_This too is good.  We do not want you to die either, and we do not have to kill you to live.  We are now friends, Captain Maverick._",15);
		add_dialog_str(1,"_We are sorry for all of the confusion you are suffering, but it is necessary.  Captain Maverick, are you willing to do us all a favor?_",15);
		add_dialog_str(2,"These people appear to be suspicious, but not necessarily bad.  Therefore, I will be suspicious to them rather than immediately violent.  Always suspicious.  I will ask them what it is that they want first.",0);
		add_dialog_choice(0,"What do you want me to do?");
		bmessage = run_dialog(1);

		set_terrain(40,17,442);
		force_instant_terrain_redraw();
		pause(5);

		reset_dialog();
		add_dialog_str(0,"_This is an emblem of Lord Ameron.  It should be familiar to you.  Place it in the center of the entrance to the Command Center.  This will be a sign of our friendship._",15);
		add_dialog_str(1,"_We're friends, Captain, and while we don't promise to tell you all of our secrets right away, one secret w'll tell you is this:  You're going to survive by doing what we say._",15);
		add_dialog_str(2,"_We don't and can't guarantee you that you'll live, but by sticking around here, it's guaranteed that you'll die.  Remember this._",15);
		add_dialog_str(3,"...  I will do this deed for them.  It does not appear to be dangerous or much of a risk, and they have provided a very good incentive to me.",0);
		add_dialog_choice(0,"Fine, I will do this thing for you.");
		bmessage = run_dialog(1);

		set_flag(1,0,5);
		block_entry(1);
	}

	if(get_flag(1,0) == 3){
		leadchar = 0;
		while(char_ok(leadchar) == FALSE){
			leadchar = (leadchar + 1);
		}
		if(item_type_in_slot(leadchar,0) == -1){
			message_dialog("I am not fully equipped yet.","");
			block_entry(1);
			end();
		}
		if(item_type_in_slot(leadchar,1) == -1){
			message_dialog("I am not fully equipped yet.","");
			block_entry(1);
			end();
		}
		if(item_type_in_slot(leadchar,5) == -1){
			message_dialog("I am not fully equipped yet.","");
			block_entry(1);
			end();
		}
		if(item_type_in_slot(leadchar,4) == -1){
			message_dialog("I am not fully equipped yet.","");
			block_entry(1);
			end();
		}
		if(item_type_in_slot(leadchar,11) == -1){
			message_dialog("I am not fully equipped yet.","");
			block_entry(1);
			end();
		}
		if(item_type_in_slot(leadchar,7) == -1){
			message_dialog("I am not fully equipped yet.","");
			block_entry(1);
			end();
		}

		set_terrain(41,19,13);
		force_view_center(42,char_loc_y(leadchar));
		force_instant_terrain_redraw();
		play_sound(59);
		pause(5);

		reset_dialog();
		add_dialog_str(0,"The soldier pulls the door shut in front of my face...  does he realize how short patience runs in this fort?",0);
		add_dialog_str(1,"_Captain Maverick._",15);
		add_dialog_choice(0,"Why did you do that?");
		bmessage = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"He does not stop to listen to me.",0);
		add_dialog_str(1,"_You are an intelligent man.  I suspect you realize the imminence of your death.  Whatever it is you want, you must first be alive to obtain it.  Whether it is riches, safety, health...  you need to be alive._",15);
		add_dialog_str(2,"_Unless you must be dead to be satisfied.  Is this the case, Captain?_",15);
		add_dialog_str(3,"This is a very odd thing to ask of me.  I suppose it is not too much of a waste of my time to oblige him.  I will tell him that I am satisfied so I may preserve morale.",0);
		add_dialog_choice(0,"I am satisfied, of course. (Lie.)");
		bmessage = run_dialog(1);

		reset_dialog();
		add_dialog_str(0,"_Do not lie to me, Captain.  I know you are lying._",15);
		add_dialog_str(1,"_Answer my question again, but this time honestly.  I'm intelligent enough to fight as best as I can.  I wanted to know what your answer to the question I asked was, not whether or not I should be spirited in combat._",15);
		add_dialog_str(2,"Fine.  I will answer him honestly; I am in no way satisfied here.",0);
		add_dialog_choice(0,"What you suspect is correct; I am not satisfied.");
		bmessage = run_dialog(1);

		set_terrain(41,19,17);
		force_view_center(42,char_loc_y(leadchar));
		force_instant_terrain_redraw();
		play_sound(58);
		pause(5);

		reset_dialog();
		add_dialog_str(0,"_Fair enough.  I am glad that you can be honest with me, Captain.  Let us make equitable deals in the near future._"15);
		add_dialog_str(1,"Without pausing, he opens the door and leaves the room.",0);
		add_dialog_choice(0,"Okay...");
		bmessage = run_dialog(1);

		relocate_character(22,21,15);
		set_character_facing(22,0);
		force_instant_terrain_redraw();
		pause(3);

		relocate_character(15,40,22);
		relocate_character(17,40,16);

		block_entry(1);
		set_flag(1,0,4);
	}

break;

beginstate 15;

	if(get_flag(1,0) >= 2){
		message_dialog("I do not have any reason to trouble General Byron any further; he is likely considering strategies to prolong Thermidor as long as is possible.","");
		block_entry(1);
	}

break;

beginstate 16;

	if(get_flag(1,0) == 6){
		reset_dialog();
		add_dialog_str(0,"There is a small indent in the floor here for the emblem to be placed.  As I place it, nothing special happens.  Certainly, whoever these _friends_ are, they could not have set up a trap to blow up in my face or anything of that nature.",0);
		add_dialog_str(1,"These _friends_ of mine are likely to have something they want me to do after this.  Do they want me to assassinate General Byron?  Do they want to kill me?  Are they just going crazy?  No, that is not likely.",0);
		add_dialog_str(2,"I should go back to them.",0);
		add_dialog_choice(0,"...");
		bmessage = run_dialog(1);

		set_terrain(24,30,442);
		set_flag(1,0,7);
		relocate_character(15,25,18);
		set_character_facing(15,6);
		relocate_character(17,28,18);
		set_character_facing(17,2);
		set_flag(1,0,7);
	}

break;

beginstate 17;

	if(get_flag(1,0) == 7){
		message_dialog("What?  They're gone.  ...now what?","");
		set_flag(1,0,8);
	}

break;

beginstate 18;

	if(get_flag(6,0) == 1){
		message_dialog("The soldier from the warehouse and the two _friends_ are standing here, each one cautiously eyeing me.","Then, before I have time to ask any of them any questions, they all go down the south to the basement level of the Command Center.");
		erase_char(9);
		erase_char(10);
		erase_char(15);
		erase_char(17);
		erase_char(21);
		erase_char(22);
		force_instant_terrain_redraw();
		set_flag(1,0,13);
		set_flag(6,0,2);
	}

break;

beginstate 19;

	if(get_flag(6,0) < 2){
		message_dialog("There is not much on this level; mostly supplies and the rear exit of the Command Center.","");
		block_entry(1);
		end();
	}
	move_to_new_town(1,32,32);

beginstate 30;

	if(get_flag(1,0) < 3){
		march_party(42,19);
		force_view_center(42,19);
		play_sound(49);
		pause(4);

		message_dialog("This is my equipment.  I should put it on before doing anything else today; while it might not always serve me in combat, it will serve my by raising the morale of my men.","");
		block_entry(1);
		set_flag(1,0,3);
	}

break;

beginstate 31;

	if(get_flag(1,0) == 5){
		reset_dialog();
		add_dialog_str(0,"This is the emblem.  The archer smiles with slight satisfaction as I pick it up.  It is not unusual in any way; it is the same as any other emblem I have seen or held.",0);
		add_dialog_str(1,"The soldier too is quiet as I hold this emblem for them.  This is no huge feat for me.  I will do this.  And yet, I suspect many things.  I also suspect that if I raised my suspicions with them, they would not tell me.",0);
		add_dialog_str(2,"This is all very strange.",0);
		add_dialog_choice(0,"...");
		bmessage = run_dialog(1);
		set_terrain(40,17,0);
		force_instant_terrain_redraw();
		pause(2);

		set_flag(1,0,6);
	}

break;

